package com.yangya.orders.controller;

import com.alibaba.fastjson.JSON;
import com.yangya.orders.feign.UserFeignClient;
import com.yangya.orders.model.vo.OrdersVo;
import com.yangya.orders.model.vo.UserVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@Slf4j
@RestController
@RequestMapping("/orders")
public class OrdersController {

    /*@Autowired
    private RestTemplate restTemplate;*/
    @Autowired
    private UserFeignClient userFeignClient;

    @GetMapping("/getOrders/{id}")
    public OrdersVo getUser(@PathVariable Long id){
       /* String forObject = this.restTemplate.getForObject("http://user/user/getUser/1", String.class);
        log.error(forObject);
        return OrdersVo.builder().id(1L).userName("2222").ordersNo("33333").build();*/
        UserVo user = userFeignClient.getUser(id);
        log.error(JSON.toJSONString(user));
        return OrdersVo.builder().id(1L).userName(user.getUserName()).ordersNo("33333").build();
    }

    @GetMapping("/test")
    public String test(){

        return "test";
    }
}
